<?php

class Theme extends Model {
	
    function Theme()
    {
        parent::Model();
    }

	function getColDir($idCol)
	{
		$sql = "SELECT DIR FROM COLLECTIONS WHERE ID=".$idCol. ";";
		
		$query = $this->db->query($sql);
		
		if ($query->num_rows() > 0)
		{
			$row = $query->row();
			return $row->DIR;		
		}else {
			return $sql;

		}
	}

	function setColTheme($idCol, $nom_theme)
	{
		$nom_theme = mysql_real_escape_string($nom_theme);
		$sql = "SELECT PACKAGES FROM COLLECTIONS WHERE ID=".$idCol. ";";
		$query = $this->db->query($sql);

		if ($query->num_rows() > 0)
		{
			$row = $query->row();
			$packages = $row->PACKAGES;	
			$packages = preg_replace('/usetheme{.*}/', 'usetheme{' .$nom_theme .'}', $packages);
			$sql = "UPDATE COLLECTIONS SET PACKAGES ='" . mysql_real_escape_string($packages) . "' WHERE ID=" .$idCol. ";";
			$query = $this->db->query($sql);
			return 1;	
		}else {
			return 0;

		}

	}
	
}
?>
